#-*- coding:utf-8 -*-
import MySQLdb

'''
1.连接数据库()
2.提供SQL语句
3.执行SQL
4.查看结果
5.断开数据
'''
#连接数据库 
conn=MySQLdb.connect(
    host="localhost",
    user="root",
    passwd="toor",
    db="test",
    charset="utf8")

cursor = conn.cursor()    

#插入一条记录

sql = "insert into proxy (id, ip, port) values ('1', '127.0.0.1', '8080')"  
n = cursor.execute(sql)
print n
conn.commit()

'''      
#更新一条记录
sql = "update user set age=1000 where Id=9"   
#n = cursor.execute(sql)   
#print n



#查询   
sql = "select name, age from user"
n = cursor.execute(sql)
rows = cursor.fetchall()
for row in rows:
    print row[0], '---', row[1]


#删除    
sql = "delete from user where id=2"   
#n = cursor.execute(sql)    
#print n

#关闭连接
conn.commit()
cursor.close()
conn.close()


CREATE TABLE `user` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `age` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ;

CIUD
CREATE
insert
update
delete
select
'''